import java.util.*;

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }

    public TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {

    public TreeNode mirrorTree(TreeNode root) {
        if (root != null) {
            TreeNode t = root.left;
            root.left = root.right;
            root.right = t;
            mirrorTree(root.left);
            mirrorTree(root.right);
        }
        return root;
    }

    public TreeNode mirrorTree2(TreeNode root) {
        Queue<TreeNode> queue = new LinkedList<>();
        if (root != null) queue.add(root);
        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();
            TreeNode t = node.left;
            node.left = node.right;
            node.right = t;
            if (node.left != null) {
                queue.add(node.left);
            }
            if (node.right != null) {
                queue.add(node.right);
            }
        }
        return root;
    }

    public static void main(String[] args) {
        TreeNode t17 = new TreeNode(7, null, null);
        TreeNode t15 = new TreeNode(15, null, null);
        TreeNode t20 = new TreeNode(20, t15, t17);
        TreeNode t9 = new TreeNode(9, null, null);
        TreeNode t3 = new TreeNode(3, t9, t20);
    }
}

